<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="项目号" prop="itCode">
      <el-input v-model="dataForm.itCode" placeholder="项目号"></el-input>
    </el-form-item>
    <el-form-item label="项目名称" prop="itDesc">
      <el-input v-model="dataForm.itDesc" placeholder="项目名称"></el-input>
    </el-form-item>
    <el-form-item label="业主ID" prop="itOwner">
      <el-input v-model="dataForm.itOwner" placeholder="业主ID"></el-input>
    </el-form-item>
    <el-form-item label="企业ID" prop="itEnterprise">
      <el-input v-model="dataForm.itEnterprise" placeholder="企业ID"></el-input>
    </el-form-item>
    <el-form-item label="企业名称" prop="itEnterprisedesc">
      <el-input v-model="dataForm.itEnterprisedesc" placeholder="企业名称"></el-input>
    </el-form-item>
    <el-form-item label="项目部署日期" prop="itDeploytime">
      <el-input v-model="dataForm.itDeploytime" placeholder="项目部署日期"></el-input>
    </el-form-item>
    <el-form-item label="项目完成日期" prop="itCompletetime">
      <el-input v-model="dataForm.itCompletetime" placeholder="项目完成日期"></el-input>
    </el-form-item>
    <el-form-item label="项目状态" prop="itStatus">
      <el-input v-model="dataForm.itStatus" placeholder="项目状态"></el-input>
    </el-form-item>
    <el-form-item label="维保状态" prop="itProtect">
      <el-input v-model="dataForm.itProtect" placeholder="维保状态"></el-input>
    </el-form-item>
    <el-form-item label="业主负责人" prop="itOwnerperson">
      <el-input v-model="dataForm.itOwnerperson" placeholder="业主负责人"></el-input>
    </el-form-item>
    <el-form-item label="业主负责电话" prop="itOwnerphone">
      <el-input v-model="dataForm.itOwnerphone" placeholder="业主负责电话"></el-input>
    </el-form-item>
    <el-form-item label="企业负责人" prop="itEnterprisepsrson">
      <el-input v-model="dataForm.itEnterprisepsrson" placeholder="企业负责人"></el-input>
    </el-form-item>
    <el-form-item label="企业负责人电话" prop="itEnterprisephone">
      <el-input v-model="dataForm.itEnterprisephone" placeholder="企业负责人电话"></el-input>
    </el-form-item>
      <el-form-item label="坐标" prop="itPoint">
        <el-input v-model="dataForm.itPoint" placeholder="坐标"></el-input>
      </el-form-item>
      <el-form-item label="查看人" prop="itUdfchar01">
        <el-input v-model="dataForm.itUdfchar01" placeholder="查看人"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          itId: 0,
          itCode: '',
          itDesc: '',
          itOwner: '',
          itEnterprise: '',
          itEnterprisedesc: '',
          itDeploytime: '',
          itCompletetime: '',
          itStatus: '',
          itProtect: '',
          itOwnerperson: '',
          itOwnerphone: '',
          itEnterprisepsrson: '',
          itEnterprisephone: '',
          itPoint: '',
          itUdfchar01:''
        },
        dataRule: {
          itCode: [
            { required: true, message: '项目号不能为空', trigger: 'blur' }
          ],
          itDesc: [
            { required: true, message: '项目名称不能为空', trigger: 'blur' }
          ]
          // itOwner: [
          //   { required: true, message: '业主ID不能为空', trigger: 'blur' }
          // ],
          // itEnterprise: [
          //   { required: true, message: '企业ID不能为空', trigger: 'blur' }
          // ],
          // itEnterprisedesc: [
          //   { required: true, message: '企业名称不能为空', trigger: 'blur' }
          // ],
          // itDeploytime: [
          //   { required: true, message: '项目部署日期不能为空', trigger: 'blur' }
          // ],
          // itCompletetime: [
          //   { required: true, message: '项目完成日期不能为空', trigger: 'blur' }
          // ],
          // itStatus: [
          //   { required: true, message: '项目状态不能为空', trigger: 'blur' }
          // ],
          // itProtect: [
          //   { required: true, message: '维保状态不能为空', trigger: 'blur' }
          // ],
          // itOwnerperson: [
          //   { required: true, message: '业主负责人不能为空', trigger: 'blur' }
          // ],
          // itOwnerphone: [
          //   { required: true, message: '业主负责电话不能为空', trigger: 'blur' }
          // ],
          // itEnterprisepsrson: [
          //   { required: true, message: '企业负责人不能为空', trigger: 'blur' }
          // ],
          // itEnterprisephone: [
          //   { required: true, message: '企业负责人电话不能为空', trigger: 'blur' }
          // ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.itId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.itId) {
            this.$http({
              url: this.$http.adornUrl(`/udp/r5rmitem/info/${this.dataForm.itId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.itCode = data.r5rmItem.itCode
                this.dataForm.itDesc = data.r5rmItem.itDesc
                this.dataForm.itOwner = data.r5rmItem.itOwner
                this.dataForm.itEnterprise = data.r5rmItem.itEnterprise
                this.dataForm.itEnterprisedesc = data.r5rmItem.itEnterprisedesc
                this.dataForm.itDeploytime = data.r5rmItem.itDeploytime
                this.dataForm.itCompletetime = data.r5rmItem.itCompletetime
                this.dataForm.itStatus = data.r5rmItem.itStatus
                this.dataForm.itProtect = data.r5rmItem.itProtect
                this.dataForm.itOwnerperson = data.r5rmItem.itOwnerperson
                this.dataForm.itOwnerphone = data.r5rmItem.itOwnerphone
                this.dataForm.itEnterprisepsrson = data.r5rmItem.itEnterprisepsrson
                this.dataForm.itEnterprisephone = data.r5rmItem.itEnterprisephone
                this.dataForm.itPoint = data.r5rmItem.itPoint
                this.dataForm.itUdfchar01 = data.r5rmItem.itUdfchar01

              }
            })
          }
        })
      },
      formatTime () {

      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/udp/r5rmitem/${!this.dataForm.itId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'itId': this.dataForm.itId || undefined,
                'itCode': this.dataForm.itCode,
                'itDesc': this.dataForm.itDesc,
                'itOwner': this.dataForm.itOwner,
                'itEnterprise': this.dataForm.itEnterprise,
                'itEnterprisedesc': this.dataForm.itEnterprisedesc,
                'itDeploytime': this.dataForm.itDeploytime,
                'itCompletetime': this.dataForm.itCompletetime,
                'itStatus': this.dataForm.itStatus,
                'itProtect': this.dataForm.itProtect,
                'itOwnerperson': this.dataForm.itOwnerperson,
                'itOwnerphone': this.dataForm.itOwnerphone,
                'itEnterprisepsrson': this.dataForm.itEnterprisepsrson,
                'itEnterprisephone': this.dataForm.itEnterprisephone,
                'itPoint': this.dataForm.itPoint,
                'itUdfchar01': this.dataForm.itUdfchar01


              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
